package com.ww.springboot.boot.thread.study.executor;

import java.util.UUID;
import java.util.concurrent.*;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-04-20 16:42
 */
public class Executor父子线程交互 {


    public static final ExecutorService ex = new ThreadPoolExecutor(8, 8, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<>());

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        Long t1 = System.currentTimeMillis();
        for (int i = 0; i < 10; i++) {
            //局部变量 每次重新生成
            ex.submit(() -> {
                //System.out.println(finalI);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

        }
        Long t2 = System.currentTimeMillis();

        for (int i = 0; i < 10; i++) {
            Future future2 = ex.submit(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                return System.currentTimeMillis() + "";
            });

            //future get 会阻塞主线程
            System.out.println(future2.get());
        }
        Long t3 = System.currentTimeMillis();

        System.out.println(t2 - t1);
        System.out.println(t3 - t2);
    }
}
